﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Data.Entity.Core.EntityClient;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.Data.EntityFramework
{
    /// <summary>
    /// Entity Framework DbContext Helper...
    /// </summary>
    public static class DbContextHelper
    {
        public static string CreateConnectionString(string connectionString)
        {
            ConnectionStringSettings backendSettings = ConfigurationManager.ConnectionStrings[connectionString];

            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(backendSettings.ConnectionString);

            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
            entityBuilder.ProviderConnectionString = sqlBuilder.ToString();
            entityBuilder.Metadata = "res://*/";
            entityBuilder.Provider = "System.Data.SqlClient";

            return entityBuilder.ToString();
        }
    }
}
